﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace DBUtil
{
    /// <summary>
    /// 批量执行sql语句项
    /// </summary>
    public class ExecuteSqlBatchItem
    {
        private ExecuteSqlBatchItem() { }

        /// <summary>
        /// Sql语句
        /// </summary>
        public string Sql { get; private set; }

        /// <summary>
        /// 参数数组
        /// </summary>
        public IDataParameter[] Parameters { get; private set; }

        /// <summary>
        /// 用于生成参数数组的字典
        /// </summary>
        public Dictionary<string, object> Dic { get; private set; }

        /// <summary>
        /// 是否直接使用参数数组
        /// </summary>
        internal bool UseParameterArray { set; get; }

        /// <summary>
        /// 创建批量执行sql语句项
        /// </summary>
        /// <returns></returns>
        public static ExecuteSqlBatchItem Create(string sql, params IDataParameter[] parameters)
        {
            return new ExecuteSqlBatchItem()
            {
                Sql = sql,
                Parameters = parameters,
                UseParameterArray = true
            };
        }

        /// <summary>
        /// 创建批量执行sql语句项
        /// </summary>
        /// <returns></returns>
        public static ExecuteSqlBatchItem Create(string sql, Dictionary<string, object> dic)
        {
            return new ExecuteSqlBatchItem()
            {
                Sql = sql,
                Dic = dic,
                UseParameterArray = false
            };
        }
    }
}
